﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace Chaos.model
{
    public class board : INotifyPropertyChanged, stream.streamable
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void Notify(string property)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }

        private stream.streamable m_oldworldmap;
        public oldworldmap Oldworldmap
        {
            get { return m_oldworldmap as oldworldmap; }
            set
            {
                if (m_oldworldmap != value)
                {
                    m_oldworldmap = value;
                    Notify("Oldworldmap");
                }
            }
        }

        private stream.streamable m_victorypointtrack;
        public victorypointtrack Victorypointtrack
        {
            get { return m_victorypointtrack as victorypointtrack; }
            set
            {
                if (m_victorypointtrack != value)
                {
                    m_victorypointtrack = value;
                    Notify("Victorypointtrack");
                }
            }
        }

        private ObservableCollection<threatdial> m_threatdials = new ObservableCollection<threatdial>();
        public ObservableCollection<threatdial> Threatdials
        {
            get { return m_threatdials; }
            set
            {
                if (m_threatdials != value)
                {
                    m_threatdials = value;
                    Notify("Threatdials");
                }
            }
        }

        private ObservableCollection<powersheet> m_powersheets = new ObservableCollection<powersheet>();
        public ObservableCollection<powersheet> Powersheets
        {
            get { return m_powersheets; }
            set
            {
                if (m_powersheets != value)
                {
                    m_powersheets = value;
                    Notify("Powersheets");
                }
            }
        }

        public virtual void serialize(stream.stream io_Stream)
        {
            io_Stream.begin("board")
                .serialize("Oldworldmap", ref m_oldworldmap)
                .serialize("victorypointtrack", ref m_victorypointtrack)
                .serialize("threatdials", ref m_threatdials)
                .serialize("powersheets", ref m_powersheets)
            .end();
        }

        public powersheet findpowersheetbyfaction(String in_name)
        {
            for (int i = 0; i < Powersheets.Count; i++)
            {
                if (Powersheets[i].Faction == in_name)
                {
                    return Powersheets[i];
                }
            }
            return null;
        }

    }
}
